﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
    class Program
    {



        static void Main(string[] args)
        {
            testSJSGF();
            //dic1.Add(b11, "string");
            //dic2.Add(b21, "string");

            Common.CodeTimer.Initialize();
       
            //Common.CodeTimer.Time("compare2", 10000000, compare2);
            //Common.CodeTimer.Time("hash1", 10000000, hash1);
            //Common.CodeTimer.Time("hash2", 10000000, hash2);
            //Common.CodeTimer.Time("testdic1", 10000000, testdic1);
            //Common.CodeTimer.Time("testdic2", 10000000, testdic2);

            //Common.CodeTimer.Time("testConvert1", 10000000, testConvert1);
            //Common.CodeTimer.Time("testConvert2", 10000000, testConvert2);
            Console.Read();
        }


        private static void testShow2003()
        {
            string file = @"\\192.168.1.134\QuotProxys\SinaQuotProxy\OutFile\SHOW2003.DBF";
            Common.CodeTimer.Time("ReadDBFHeader_Show2003", 100, () => { ReadDBFHeader_Show2003(file); });
        }
        private static void ReadDBFHeader_Show2003(string file)
        {
            var bytes = Common.FileReader.ReadAllBytes(file);
            Common.DBFHelper.DbfHeader header;
            List<Common.DBFHelper.DbfColumn> columns;
            Common.DBFHelper.DBFReader.ReadHeader(bytes, out header, out columns);
            List<Common.DBFHelper.Show2003Record> records;
            Common.DBFHelper.DBFReader.ReadRecords<Common.DBFHelper.Show2003Record>(bytes, header, columns, out records);
        }

        private static void testSJSGF()
        {
            string file = @"C:\Users\limeng\Desktop\SJSGF.dbf";

            Common.CodeTimer.Time("ReadDBFHeader_SJSGF", 100, () => { ReadDBFHeader_SJSGF(file); });
        }
        private static void ReadDBFHeader_SJSGF(string file)
        {

            var bytes = Common.FileReader.ReadAllBytes(file);

            Common.DBFHelper.DbfHeader header;
            List<Common.DBFHelper.DbfColumn> columns;
            Common.DBFHelper.DBFReader.ReadHeader(bytes, out header, out columns);
            List<Common.DBFHelper.SJSGFRecord> records;
            Common.DBFHelper.DBFReader.ReadRecords<Common.DBFHelper.SJSGFRecord>(bytes, header, columns, out records);
        }

        static Test.Compare.BSType b11 = Test.Compare.BSType.Buy;
        static Test.Compare.BSType b12 = Test.Compare.BSType.Sell;

        static BSFlag b21 = BSFlag.B;
        static BSFlag b22 = BSFlag.S;

        static Dictionary<Test.Compare.BSType, string> dic1 = new Dictionary<Compare.BSType, string>();
        static Dictionary<BSFlag, string> dic2 = new Dictionary<BSFlag, string>();

        private static void compare1()
        {
            bool eq = b11.Equals(b12);
        }
        private static void compare2()
        {
            bool eq = b21.Equals(b22);
        }

        private static void hash1()
        {
            int eq = b11.GetHashCode();
        }
        private static void hash2()
        {
            int eq = b21.GetHashCode();
        }


        private static void testdic1()
        {
            string rtn;
            dic1.TryGetValue(b11, out rtn);
        }
        private static void testdic2()
        {
            string rtn;
            dic2.TryGetValue(b21, out rtn);
        }


        private static void testConvert1()
        {
            Test.Compare.BSType f;
            bool s = Test.Compare.BSType.Manager.TryGetFlag('B', out f);
        }
        private static void testConvert2()
        {
            BSFlag f;
            bool s = BSFlag.TryConvert('B', out f);
        }
    }
    public sealed class BSFlag : Common.FlexibleFlagBase<char, BSFlag>
    {
        private BSFlag(char value) : base(value) { }

        public static readonly BSFlag B = new BSFlag('B');

        public static readonly BSFlag S = new BSFlag('S');
    }


}
